package com.szty.libarytest.other

import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.Bundle
import android.os.IBinder
import androidx.appcompat.app.AppCompatActivity
import com.szty.libarytest.R
import com.szty.libarytest.longConnect.DotBean
import com.szty.libarytest.longConnect.manager.SendPointService
import kotlinx.android.synthetic.main.activity_long_connect.*

class LongConnect2Activity : AppCompatActivity() {
    private var mService: SendPointService.SendBind? = null
    private val mServiceConnection by lazy {
        object : ServiceConnection {
            override fun onServiceDisconnected(name: ComponentName?) {}
            override fun onServiceConnected(name: ComponentName, service: IBinder) {
                if (service is SendPointService.SendBind) {
                    mService = service
                }
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_long_connect)
        bindService(
            Intent(this, SendPointService::class.java),
            mServiceConnection,
            Context.BIND_AUTO_CREATE
        )

        btn_send_message.setOnClickListener {
            mService?.sendPointToService(DotBean())
        }
    }
}